import request from "@/utils/request";

/**
 *
 * @returns {Promise | Promise<unknown>}
 */
export function getAddShipmentData(){
  return request({
    url: '/shipment/getAddShipmentData',
    method: 'get',
  })
}

export function getShipmentList(params = {}){
  return request({
    url: `/shipment/getShipmentList`,
    method: 'get',
    params,
  })
}


export function getShipmentGoods(params = {}){
  return request({
    url: `/shipment/getShipmentGoods`,
    method: 'get',
    params
  })
}

/**
 * 保存货件单
 * @param data
 * @returns {Promise | Promise<unknown>}
 */
export function saveShipment(data){
  return request({
    url: `/shipment/saveShipment`,
    method: 'post',
    data,
    handleError: true,
  })
}

/**
 * 保存货件单
 * @param data
 * @returns {Promise | Promise<unknown>}
 */
export function SaveShipmentBoxData(data){
  return request({
    url: `/shipment/SaveShipmentBoxData`,
    method: 'post',
    data,
    handleError: true,
  })
}

/**
 * 撤销货件
 * @param id
 * @returns {Promise | Promise<unknown>}
 */
export function deleteShipment(id){
  return request({
    url: `/shipment/deleteShipment/${id}`,
    method: 'delete',
    handleError: true,
  })
}

/**
 * 获取详情
 * @param id
 * @returns {Promise | Promise<unknown>}
 */
export function getShipmentInfo(id){
  return request({
    url: `/shipment/getShipmentInfo/${id}`,
  })
}


/**
 * 修改货件
 * @param data
 * @returns {Promise | Promise<unknown>}
 */
export function  editShipment(data){
  return request({
    url: `/shipment/editShipment`,
    method: 'post',
    data,
    handleError: true,
  })
}

/**
 * 获取店铺数量
 * @param params
 * @returns {Promise<unknown>}
 */
export function getShipmentAccountSkuNum(params){
  return request({
    url: `/shipment/getShipmentAccountSkuNum`,
    method: 'get',
    params,
  })
}

/**
 * 获取货件商品
 * @param params
 * @returns {Promise<unknown>}
 */
export function getShipmentGoodsList(params){
  return request({
    url: '/shipment/getShipmentGoodsList',
    method:'get',
    params
  })
}

/**
 * 获取仓库商品
 * @param params
 * @returns {Promise | Promise<unknown>}
 */
export function getWarehouseGoodsList(params){
  return request({
    url: '/shipment/getWarehouseGoodsList',
    method: 'get',
    params
  })
}

/**
 * 获取官方仓商品
 * @param params
 * @returns {Promise<unknown>}
 */
export function getFullGoodsList(params){
  return request({
    url: '/shipment/getFullGoodsList',
    params
  })
}

/**
 * 作废送仓货件
 * @param id
 * @returns {Promise<unknown>}
 */
export function cancelShipment(id){
  return request({
    url: `/shipment/cancelShipmentById/${id}`,
    method: 'patch',
    handleError: true,
  })
}


/**
 * 打印箱标
 * @param id
 * @returns {Promise | Promise<unknown>}
 */
export function printShipmentBoxPDF(id){
  return request({
    url: `/shipment/printShipmentBoxPDF/${id}`,
    method: 'get',
    responseType: "arraybuffer",
    isNotJson: true,
    timeout: 60000 * 5, // 1分钟
    handleError: true,
  })
}


/**
 * 获取货件单商品详情
 * @param params
 * @returns {Promise | Promise<unknown>}
 */
export function getShipmentGoodsPage(params){
  return request({
    url: '/shipment/getShipmentGoodsPage',
    params,
  })
}

/**
 * 修改货件里面的货值
 * @param data
 * @returns {Promise | Promise<unknown>}
 */
export function updateShipmentGoodsValue(data){
  return request({
    url: `/shipment/updateShipmentGoodsValue`,
    data,
    method: 'patch',
  })
}

/**
 * 获取添加货件单入库商品类型（整箱/混箱）
 * @param params
 * @returns {Promise | Promise<unknown>}
 */
export function getShipmentTableType(params){
  return request({
    url: `/shipment/getShipmentTableType`,
    params,
    method: 'get',
  })
}
